package com.ksy.common.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.ksy.common.R;
import com.ksy.common.pick.WheelView;
import com.ksy.common.pick.adapters.ArrayWheelAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Ksy.
 */

public class NumChooseDialog extends BottomDialog {

    private ClickListener onClickListener;
    private List<Integer> numList = new ArrayList<>();
    private WheelView wheelFirst;

    public NumChooseDialog(Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.common_layout_dialog_picker_num_bottom);
        View dialog_cancel = findViewById(R.id.dialog_cancel);
        View dialog_enter = findViewById(R.id.dialog_enter);
        wheelFirst = findViewById(R.id.wheelFirst);
        dialog_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        dialog_enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int current = wheelFirst.getCurrentItem();
                if (current >= 0 && current < numList.size()) {
                    Integer integer = numList.get(current);
                    if (onClickListener != null) {
                        onClickListener.enter(NumChooseDialog.this, integer);
                    }
                }
            }
        });
        setUpData();
    }


    private void setUpData() {
        for (int i = 18; i < 108; i++) {
            numList.add(i);
        }
        wheelFirst.setViewAdapter(new ArrayWheelAdapter<>(getContext(), numList));
        wheelFirst.setVisibleItems(7);
    }


    public void setOnClickListener(ClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface ClickListener {
        void enter(BaseDialog dialog, int num);
    }
}
